package com.study.jdbc.factory;

import com.study.jdbc.dao.CustomerDao;
import com.study.jdbc.service.CustomerService;
import com.study.jdbc.utils.ResourceBundleUtil;

public class BeanFactory {
	
	private static BeanFactory beanFactory = null ; 
	
	private BeanFactory() {}
	
	public static BeanFactory getInstance() {
		if(beanFactory != null) {
			return beanFactory ;
		} 
		return new BeanFactory() ;
	}
	
	/**
	* @Name: getCustomerDaoImpl
	* @Description: 获取CustomerDao接口的实现类对象
	* @Author: 李超	lc_jack@foxmail.com
	* @Version: V1.0
	* @CreateDate: 2017-2-16 下午8:31:41
	* @Parameters: @return
	* @Return: CustomerDao
	 */
	public static CustomerDao getCustomerDaoImpl() {
		CustomerDao customerDao = null ;
		String CustomerDaoImplName = ResourceBundleUtil.getValueByKey("CustomerDaoImpl") ;
		try {
			customerDao = (CustomerDao) Class.forName(CustomerDaoImplName).newInstance() ;
		} catch (InstantiationException | IllegalAccessException
				| ClassNotFoundException e) {
			System.out.println("CustomerDao接口的实现类对象实例创建失败！");
			e.printStackTrace();
		}
		return customerDao ;
	}
	
	/**
	* @Name: getCustomerServiceImpl
	* @Description: 获取CustomerService接口的实现类对象
	* @Author: 李超	lc_jack@foxmail.com
	* @Version: V1.0
	* @CreateDate: 2017-2-16 下午8:45:51
	* @Parameters: @return
	* @Return: CustomerService
	 */
	public static CustomerService getCustomerServiceImpl() {
		CustomerService customerService = null ;
		String CustomerServiceImplName = ResourceBundleUtil.getValueByKey("CustomerServiceImpl") ;
		try {
			customerService = (CustomerService) Class.forName(CustomerServiceImplName).newInstance() ;
		} catch (InstantiationException | IllegalAccessException
				| ClassNotFoundException e) {
			System.out.println("CustomerService接口的实现类对象实例创建失败！");
			e.printStackTrace();
		}
		return customerService ;
	}

}
